/*
 * HWTIMERC1.h
 *
 *  Created on: 27/02/2013
 *      Author: RIchard
 */

#ifndef HWTIMERC1_H_
#define HWTIMERC1_H_

#include <msp430.h>
#include "../../cdef.h"

#define HWTIM_nTimerInterval  10    /* in miliseconds */
#define HWTIM_nPWMFreq        1000  /* in Hz */

typedef struct
{
   uint16 biTAIFG    :1;
   uint16 biTAIE     :1;
   uint16 biTACLR    :1;
   uint16            :1;
   uint16 u2MC       :2;
   uint16 u2ID       :2;
   uint16 u2TASSEL   :2;
   uint16            :6;
} MSP430_tstTACTL;

typedef struct
{
   uint16 biCCIFG    :1;
   uint16 biCOV      :1;
   uint16 biOUT      :1;
   uint16 biCCI      :1;
   uint16 biCCIE     :1;
   uint16 u3OUTMOD   :3;
   uint16 biCAP      :1;
   uint16            :1;
   uint16 biSCCI     :1;
   uint16 biSCS      :1;
   uint16 u2CCIS     :2;
   uint16 u2CM       :2;
} MSP430_tstTACCTL;

typedef struct
{
   uint16 u3TAIDEX   :3;
   uint16 u13Reserved:13;
} MSP430_tstTAEX0;

typedef struct
{
   MSP430_tstTACTL   TACTL;      /* 00h */
   MSP430_tstTACCTL  TACCTL[7];  /* 02h - 0Eh */
   uint16            TAR;        /* 10h */
   uint16            TACCR[7];   /* 12h - 1Eh */
   MSP430_tstTAEX0   TAEX0;      /* 20h */
   uint16            :16;        /* 22h */
   uint16            :16;        /* 24h */
   uint16            :16;        /* 26h */
   uint16            :16;        /* 28h */
   uint16            :16;        /* 2Ah */
   uint16            :16;        /* 2Ch */
   uint16            TAIV;       /* 2Eh */
} MSP430_tstTimerARegisters;

typedef enum
{
   HWTIM_nenTACLK       = 0u,
   HWTIM_nenACLK        = 1u,
   HWTIM_nenSMCLK       = 2u,
   HWTIM_nenInvTACLK    = 3u
} HWTIM_tenTimerAClkSrc;

typedef enum
{
   HWTIM_nenStop        = 0u,
   HWTIM_nenUp          = 1u,
   HWTIM_nenContinuous  = 2u,
   HWTIM_nenUpDown      = 3u
} HWTIM_tenTimerAModeControl;

typedef enum
{
   HWTIM_nenOUT         = 0u,
   HWTIM_nenSet         = 1u,
   HWTIM_nenToggleReset = 2u,
   HWTIM_nenSetReset    = 3u,
   HWTIM_nenToggle      = 4u,
   HWTIM_nenReset       = 5u,
   HWTIM_nenToggleSet   = 6u,
   HWTIM_nenResetSet    = 7u
} HWTIM_tenTimerAOutputMode;

#define MSP430_TIMERA0  (*((volatile MSP430_tstTimerARegisters*)__MSP430_BASEADDRESS_T0A5__))
#define MSP430_TIMERA1  (*((volatile MSP430_tstTimerARegisters*)__MSP430_BASEADDRESS_T1A3__))

void HWTIM_vReset( void );
void HWTIM_vStartPWM( void );
void HWTIM_vStartTimer( void );
void HWTIM_vStopTimer( void );
bool HWTIM_boIsTimerRunning( void );
uint16 HWTIM_u16GetCurrentTimerValue( void );
uint16 HWTIM_u16GetCounterValue( void );
void HWTIM_vClearCounterValue( void );

#endif /* HWTIMERC1_H_ */
